//
//  ModifyPasswordController.m
//  collection
//
//  Created by zhangjing on 12/21/11.
//  Copyright (c) 2011 Tsinghua University. All rights reserved.
//

#import "ModifyPasswordController.h"

@interface ModifyPasswordController()

@property (retain, nonatomic) IBOutlet UITableView *contentTableView;
@property (retain, nonatomic) IBOutlet UILabel *oldPassLabel;
@property (nonatomic, strong)   IBOutlet    UITextField*    oldPassTextField;
@property (retain, nonatomic) IBOutlet UILabel *nowPassLabel;
@property (nonatomic, strong)   IBOutlet    UITextField*    nowPassTextField;
@property (retain, nonatomic) IBOutlet UILabel *repeatNewLabel;
@property (nonatomic, strong)   IBOutlet    UITextField*    repeatNowPassTextField;

- (IBAction)onClickFinishModifyBarButton:(id)sender;
- (IBAction)onClickBactBarItem:(id)sender;

@end

@implementation ModifyPasswordController

@synthesize contentTableView = _contentTableView;
@synthesize oldPassLabel = _oldPassLabel;
@synthesize oldPassTextField        = _oldPassTextField;
@synthesize nowPassLabel = _nowPassLabel;
@synthesize nowPassTextField        = _nowPassTextField;
@synthesize repeatNewLabel = _repeatNewLabel;
@synthesize repeatNowPassTextField  = _repeatNowPassTextField;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc {
    
    self.oldPassTextField       = nil;
    self.nowPassTextField       = nil;
    self.repeatNowPassTextField = nil;
    
    [_contentTableView release];
    [_oldPassLabel release];
    [_nowPassLabel release];
    [_repeatNewLabel release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.contentTableView.backgroundColor = [UIColor clearColor];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"all_bg"]];
}

- (void)viewDidUnload
{
    [self setContentTableView:nil];
    [self setOldPassLabel:nil];
    [self setNowPassLabel:nil];
    [self setRepeatNewLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.oldPassTextField       = nil;
    self.nowPassTextField       = nil;
    self.repeatNowPassTextField = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Implementation of UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString* manageCellID = @"ModifyPasswordCell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:manageCellID];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:manageCellID] autorelease];
        
        if (indexPath.row == 0) {
            self.oldPassLabel.frame = CGRectMake(25, 5, 100, 34);
            [cell.contentView addSubview:self.oldPassLabel];
            
            self.oldPassTextField.frame = CGRectMake(130, 5, 140, 34);
            [cell.contentView addSubview:self.oldPassTextField];
        }
        else if (indexPath.row == 1) {
            self.nowPassLabel.frame = CGRectMake(25, 5, 100, 34);
            [cell.contentView addSubview:self.nowPassLabel];
            
            self.nowPassTextField.frame = CGRectMake(130, 5, 140, 34);
            [cell.contentView addSubview:self.nowPassTextField];
        }
        else if (indexPath.row == 2) {
            self.repeatNewLabel.frame = CGRectMake(25, 5, 100, 34);
            [cell.contentView addSubview:self.repeatNewLabel];
            
            self.repeatNowPassTextField.frame = CGRectMake(130, 5, 140, 34);
            [cell.contentView addSubview:self.repeatNowPassTextField];
        }
    }
   
    return cell;
}

#pragma mark - Private methods

- (IBAction)onClickBactBarItem:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

- (IBAction)onClickFinishModifyBarButton:(id)sender {
    
    // Check the new password
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

@end
